<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {


	//验证用户是否登录
    public function _initialize(){
    	
        if(!isset($_SESSION['admin'])) $this->redirect('Login/index');
    }



    public function index(){

    	$list=M('From')->select();

    	$count=M('From')->count();
    	
    	$this->assign('count',$count);
    	$this->assign("list",$list);

    	$this->display();
    }



    public function state_edit(){

    	if(IS_POST && I('id')){

    		$F=M('From');

    		$res=$F->where(array('id'=>I('id')))->find();

    		if($res['state']=='1'){
    			$data['state']='0';
    		}else{
    			$data['state']='1';
    		}

    		$r=$F->where(array('id'=>I('id')))->save($data);
    		if($r) $this->ajaxReturn($data);

    	}
    }



    public function delete(){
    	if(IS_POST && I('id')){

    		$res=M('From')->where(array('id'=>I('id')))->delete();
    		if($res) $this->ajaxReturn($res);
    	}
    }



}